<%-- 
    Document   : Admin
    Created on : Jun 1, 2013, 5:03:09 PM
    Author     : quannq
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/reset.css" type="text/css"/>
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/compact.css" type="text/css"/>        
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css" type="text/css"/>
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/tables.css" type="text/css"/>
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/modal.css" type="text/css"/>
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/pygments.css" type="text/css"/>
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/validationEngine.jquery.css" type="text/css" />
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.2.min.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.dataTables.min.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.dataTables.nightly.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/modal.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.validationEngine-en.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.validationEngine.js"></script>
        <title>Admin</title>
        <script type="text/javascript" charset="utf-8">
            jQuery(document).ready(function() {
                // binds form submission and fields to the validation engine
                jQuery("#validate").validationEngine();
            });
            $(document).ready(function() {
                $('.example').dataTable({
                    "aaSorting": [[0, "desc"]],
                    "fnRowCallback": function(nRow, aData, iDisplayIndex) {
                        var index = 0;
                        var subscriberId = aData[index];

                        return nRow;
                    },
                    "aoColumnDefs": [{
                            "aTargets": [0]
                        }],
                    "sPaginationType": "full_numbers"
                });
            });

            function modalFormAdd(action) {
                // Create a modal instance.
                var $m = $('body').modal(),
                        // Access an instance API
                        api = $m.data('modal');

                // Bind a click event to copy a hidden elements content into the modal window
                $.ajax({
                    url: '${pageContext.request.contextPath}/admin/' + action,
                    success: function(data) {
                        if (api.isOpen) {
                            api.update(data);
                        } else {
                            api.open(data);
                        }
                        jQuery("#validate").validationEngine();
                    },
                    error: function(xhr, error) {
                        console.log(error);
                    }
                });
            }
            function modalFormUpdate(action, id) {
                // Create a modal instance.
                var $m = $('body').modal(),
                        // Access an instance API
                        api = $m.data('modal');

                // Bind a click event to copy a hidden elements content into the modal window
                $.ajax({
                    url: '${pageContext.request.contextPath}/admin/' + action + '/' + id,
                    success: function(data) {
                        if (api.isOpen) {
                            api.update(data);
                        } else {
                            api.open(data);
                        }
                        jQuery("#validate").validationEngine();
                    },
                    error: function(xhr, error) {
                        console.log(error);
                    }
                });
            }
            function deleteRecord(div, action, id) {
                $.ajax({
                    type: "get",
                    url: "${pageContext.request.contextPath}/admin/" + action + "/" + id,
                    success: function(response) {
                        $(div).html("");
                        $(div).html(response);
                    },
                    error: function() {
                        alert('Error while request..');
                    }
                });

            }
            function loadList(div, action, id) {
                $.ajax({
                    type: "get",
                    url: "${pageContext.request.contextPath}/admin/" + action + "/" + id,
                    success: function(response) {
                        $('#' + div).html("");
                        $('#' + div).html(response);
                    },
                    error: function() {
                        alert('Error while request..');
                    }
                });
            }
            function hideTag(tagID) {
                $('#' + tagID).html("");
            }

            function updateSelectTag(tagID) {
                $('#' + tagID).html("<select style='width:215px'><option value=''>Select</option></select>");
            }

        </script>
    </head>
    <body style="background-image: url(${pageContext.request.contextPath}/image/bg.jpg);">
        <jsp:include page="layout/MenuAdmin.jsp"/>
        <div style="width: 1000px;margin: auto">
            <c:if test="${not empty adminpage}">
                <jsp:include page="admin/${adminpage}" flush="true" />
            </c:if>
        </div>
    </body>
</html>
